package com.leetcode;

import java.util.List;

public class L0144 {

}
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
class Solution {
    List<Integer> list;
    public List<Integer> preorderTraversal(TreeNode root) {
         if (root==null)
             return null;
         per(root);
         return list;
    }

    public void per(TreeNode root){
         list.add(root.val);
         if (root.left!=null)
             per(root.left);
         if (root.right!=null)
             per(root.right);
    }
}